#pragma once

#include "cartographer/rcm/particle_filter/common.h"

namespace cartographer
{
    typedef std::function<Particle::Ptr()> ParticleGenerateFunc;
    typedef std::function<double(const Particle::Ptr &)> ParticleWeightFunc;

    class ParticleFilter
    {
    public:
        using Ptr = std::shared_ptr<ParticleFilter>;

        ParticleFilter(int particle_num)
            : particle_num_(particle_num)
            , initialized_(false)
        {
        }

        virtual ~ParticleFilter()
        {
        }

        bool Initiate(const ParticleGenerateFunc &generator);

        void UpdateWeight(const ParticleWeightFunc &weight);

        virtual void Resample() = 0;

        inline bool Initialized() const
        {
            return initialized_;
        }

    protected:
        bool initialized_ = false;
        int particle_num_ = 0;
        std::vector<double> weights;
        std::vector<Particle::Ptr> particles;
    };
} // namespace cartographer